//
//  sightseeingInfo.m
//  ElektroM
//
//  Created by Michael on 03.11.09.
//  Copyright 2009 Artgruppe inc. All rights reserved.
//

#import "sightseeingInfo.h"
#import "infoSSView.h"


@implementation sightseeingInfo
@synthesize containerView;
@synthesize captionView, contentView;
@synthesize strCaption, strContents;
@synthesize reflectionView;

#define reflectionFraction 0.35
#define reflectionOpacity 0.5
#define kTransitionDuration	0.75

- (id)init {
	if (self = [super init]) {		
		
	}
	return self;
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {	
	//printf("Ended...\n");
	[self kurlCurrentView];
}


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	// create and store a container view
	self.navigationItem.title=NSLocalizedString(@"Info", @"");
	UIView *localContainerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
	self.containerView = localContainerView;
	[localContainerView release];
	
	containerView.backgroundColor = [UIColor whiteColor];
	CGSize preferredElementViewSize = [infoSSView preferredViewSize];
	
	CGRect viewRect = CGRectMake((containerView.bounds.size.width-preferredElementViewSize.width)/2,
								 (containerView.bounds.size.height-preferredElementViewSize.height)/2-40,
								 preferredElementViewSize.width,preferredElementViewSize.height);
	
	infoSSView* caption=[[infoSSView alloc] initWithFrame:viewRect];
	self.captionView=caption;
	[caption release];
	
	captionView.strShow = strCaption;	
	[containerView addSubview:captionView];
	
	infoSSView* contents=[[infoSSView alloc] initWithFrame:viewRect];
	self.contentView = contents;
	[contents release];
	
	contentView.strShow = strContents;	
	self.view = containerView;
	
	// create the reflection view
	CGRect reflectionRect=viewRect;
	
	// the reflection is a fraction of the size of the view being reflected
	reflectionRect.size.height=reflectionRect.size.height*reflectionFraction;
	
	// and is offset to be at the bottom of the view being reflected
	reflectionRect=CGRectOffset(reflectionRect,0,viewRect.size.height);
	
	UIImageView *localReflectionImageView = [[UIImageView alloc] initWithFrame:reflectionRect];
	self.reflectionView = localReflectionImageView;
	[localReflectionImageView release];
	
	// determine the size of the reflection to create
	NSUInteger reflectionHeight=captionView.bounds.size.height*reflectionFraction;
	
	// create the reflection image, assign it to the UIImageView and add the image view to the containerView
	reflectionView.image=[self.captionView reflectedImageRepresentationWithHeight:reflectionHeight];
	reflectionView.alpha=reflectionOpacity;
	
	[containerView addSubview:reflectionView];	
	//[self.view addSubview:self.containerView];
}



- (void)kurlCurrentView {
	
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:kTransitionDuration];
	
	[UIView setAnimationTransition:([self.captionView superview] ?
									UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)
						   forView:self.containerView cache:YES];
	if ([self.contentView superview])
	{
		[self.contentView removeFromSuperview];
		[self.containerView addSubview:self.captionView];
	}
	else
	{
		[self.captionView removeFromSuperview];
		[self.containerView addSubview:self.contentView];
	}
	
	[UIView commitAnimations];	
}

- (void)viewWillAppear:(BOOL)animated{
	//[self.navigationController setToolbarHidden:NO];
	[self.navigationController setNavigationBarHidden:NO animated:YES];
	//if(_diAllStationsWithIndexes==nil)
	//[self loadAllNeededElements:_db];
}
/*
- (void)viewWillDisappear:(BOOL)animated{
	//[self.navigationController setToolbarHidden:YES];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    //[self releaseUnneededElements];
}
 */

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
	
	//[self.captionView release];
	self.captionView = nil;
	
	//[self.contentView release];
	self.contentView = nil;
	
	//[self.reflectionView release];
	self.reflectionView = nil;
	
	//[self.contentView release];
	self.contentView=nil;
	 
}


- (void)dealloc {
	[self.captionView release];
	[self.contentView release];	
	[self.reflectionView release];
	[self.contentView release];
	
    [super dealloc];
	
}


@end
